// my_custom_msgs_pub.cpp
#include <rclcpp/rclcpp.hpp>
#include "my_custom_msgs/msg/my_custom_msg.hpp"

class CustomMsgPublisher : public rclcpp::Node {
public:
    CustomMsgPublisher() : Node("custom_msg_publisher") {
        publisher_ = this->create_publisher<my_custom_msgs::msg::MyCustomMsg>("custom_topic", 10);
        timer_ = this->create_wall_timer(
            std::chrono::seconds(1),
            std::bind(&CustomMsgPublisher::publish_message, this)
        );
    }

private:
    void publish_message() {
        auto message = my_custom_msgs::msg::MyCustomMsg();
        message.id = 1;
        message.name = "example";
        message.value = 42.0;
        RCLCPP_INFO(this->get_logger(), "Publishing: id=%d, name=%s, value=%f",
                    message.id, message.name.c_str(), message.value);
        publisher_->publish(message);
    }

    rclcpp::Publisher<my_custom_msgs::msg::MyCustomMsg>::SharedPtr publisher_;
    rclcpp::TimerBase::SharedPtr timer_;
};

int main(int argc, char * argv[]) {
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<CustomMsgPublisher>());
    rclcpp::shutdown();
    return 0;
}
